import 'dart:io';

import 'package:fluro/fluro.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:hxdj/common/components/my_tap_widget.dart';
import 'package:hxdj/common/components/my_text.dart';
import 'package:hxdj/common/components/my_webview.dart';
import 'package:hxdj/common/my_common.dart';
import 'package:hxdj/common/my_constant.dart';
import 'package:hxdj/common/my_global.dart';
import 'package:hxdj/common/my_header_global.dart';
import 'package:hxdj/common/routers/navigator.dart';
import 'package:hxdj/login/login_page.dart';

///用户协议与隐私政策
class UserAgreementPage extends StatelessWidget {
  const UserAgreementPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: MyColours.materialBg,
      padding: EdgeInsets.all(30.0.w),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          ///title
          const SizedBox(height: kToolbarHeight),

          MyText("用户协议与隐私政策", fontSize: 22.sp, color: MyColours.textBlack, fontWeight: FontWeight.w500),

          //内容
          Container(
            padding: EdgeInsets.only(top: 25.h),
            child: Text(
              "感谢您下载欢心到家。在您开始使用本软件时，我们可能会对您的部分个人信息进行收集、使用和共享。",
              style: TextStyle(fontSize: 15.sp, color: MyColours.textBlack, height: 1.5),
            ),
          ),

          Container(
            padding: EdgeInsets.only(top: 25.h),
            child: RichText(
                text: TextSpan(style: TextStyle(color: MyColours.textBlack, fontSize: 15.sp, height: 1.5), children: [
              const TextSpan(text: '请您务必仔细阅读'),
              TextSpan(
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {

                      NavigatorUtils.pushParams(context, MyWebviewPage.routeName,
                          params: {"title": "用户协议", "url": MyConstant.userAgreementUrl});

                    },
                  text: '《用户协议》',
                  style:
                      TextStyle(color: MyColours.appMain, fontSize: 15.sp, height: 1.5, fontWeight: FontWeight.w700)),
              const TextSpan(text: '与'),
              TextSpan(
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      NavigatorUtils.pushParams(context, MyWebviewPage.routeName,
                          params: {"title": "隐私政策", "url": MyConstant.privacyPolicyUrl});
                    },
                  text: '《隐私政策》',
                  style:
                      TextStyle(color: MyColours.appMain, fontSize: 15.sp, height: 1.5, fontWeight: FontWeight.w700)),
              const TextSpan(text: '全文，并确定完全了解我们对您个人信息的处理规则。'),
            ])),
          ),

          Container(
            padding: EdgeInsets.only(top: 25.h),
            child: RichText(
                text: TextSpan(style: TextStyle(color: MyColours.textBlack, fontSize: 15.sp, height: 1.5), children: [
              const TextSpan(text: '如您同意'),
              TextSpan(
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                
                      NavigatorUtils.pushParams(context, MyWebviewPage.routeName,
                          params: {"title": "用户协议", "url": MyConstant.userAgreementUrl});
                    },
                  text: '《用户协议》',
                  style:
                      TextStyle(color: MyColours.appMain, fontSize: 15.sp, height: 1.5, fontWeight: FontWeight.w700)),
              const TextSpan(text: '与'),
              TextSpan(
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      NavigatorUtils.pushParams(context, MyWebviewPage.routeName,
                          params: {"title": "隐私政策", "url": MyConstant.privacyPolicyUrl});
                    },
                  text: '《隐私政策》',
                  style:
                      TextStyle(color: MyColours.appMain, fontSize: 15.sp, height: 1.5, fontWeight: FontWeight.w700)),
              const TextSpan(text: '请点击”同意’开始使用我们的产品和服务，我们会尽全力保护您的个人信息安全。'),
            ])),
          ),

          SizedBox(height: 90.h),

          ///按钮
          Container(
            padding: EdgeInsets.symmetric(horizontal: 10.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                ///不同意
                SizedBox(
                  width: 130.w,
                  height: 45.w,
                  child: MyTapWidget(
                      onTap: () {
                        //不同意, 退出APP
                        exit(0);
                      },
                      child: MyBorder(
                        backgroundColor: MyColours.appMain.withOpacity(0.5),
                        color: MyColours.appMain,
                        radius: 45.w / 2,
                        child: Container(
                          alignment: Alignment.center,
                          child: Text(
                            "不同意并退出",
                            style: TextStyle(color: MyColours.materialBg, fontSize: 15.sp),
                          ),
                        ),
                      )),
                ),

                ///同意
                SizedBox(
                  width: 130.w,
                  height: 45.w,
                  child: MyTapWidget(
                      onTap: () {
                        //同意, 进入APP
                        //给全局的Provider 赋值
                        MyGlobalViewModel globalViewModel = MyGlobalViewModel.getGlobalViewModel(context);

                        CommonPlugin.sharedPreferences!.setBool(MyConstant.isAgreeUserAgreement, true);
                        globalViewModel.isAgreeUserAgreement = true;
                        globalViewModel.refresh();
                        //跳转到主页面
                        NavigatorUtils.pushParams(context, LoginPage.routeName,
                            clearStack: true, replace: true, transition: TransitionType.fadeIn);
                      },
                      child: MyBorder(
                        backgroundColor: MyColours.appMain,
                        color: MyColours.appMain,
                        radius: 45.w / 2,
                        child: Container(
                          alignment: Alignment.center,
                          child: Text(
                            "同意",
                            style: TextStyle(color: MyColours.materialBg, fontSize: 15.sp),
                          ),
                        ),
                      )),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
